import utils from './utils'
import Cnode from './Cnode'
import Div from './Div'

export default class World extends Cnode{
    constructor(ctx, width = 375, height = 667){
        super()
        utils.define(this, {ctx, tagName: 'world'}, {readonly: true})
        utils.define(this, {width, height})
    }
    create(tagName, style) {
        let el = null
        switch(tagName){
            case 'div':
                el = new Div(style)
            break
            case 'img':
            break
        }
        if(!el) return el
        el.parent = this
        this.children.push(el)
        return el
    }
    render(){
        for (let i = 0, len = this.children.length; i < len; i++) {
            if (this.children[i].render) this.children[i].render(this.ctx)
        }
        if (this.ctx.draw) this.ctx.draw()
    }
}